#include "gt30l32.h"

void GT_SendAddr(uint32_t addr)
{
  uint8_t com[5];
  com[0] = 0x0b;
  com[1] = addr >> 16;
  com[2] = addr >> 8;
  com[3] = addr;
  com[4] = 0xff;
  HAL_SPI_Transmit(&hspi1, com, 5, 0xff);
}

void GT_FontGetHZ12(uint16_t str, uint8_t* font)
{
  uint32_t Address;
  uint8_t MSB, LSB;
  MSB = str>>8;
  LSB = str;
  if(MSB > 0xa0 && MSB < 0xaa)
    Address = ((MSB - 0xa1) * 94 + LSB - 0xa1) * 24 + BaseAdd_12X12;
  else
    Address = ((MSB - 0xb0) * 94 + LSB - 0xa1 + 846) * 24 + BaseAdd_12X12;
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_RESET);
  GT_SendAddr(Address);
  HAL_SPI_Receive(&hspi1, font, 24, 0xff);
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_SET);
}

void GT_FontGetHZ16(uint16_t str, uint8_t* font)
{
  uint32_t Address;
  uint8_t MSB, LSB;
  MSB = str>>8;
  LSB = str;
  if(MSB > 0xa0 && MSB < 0xaa)
    Address = ((MSB - 0xa1) * 94 + LSB - 0xa1) * 32 + BaseAdd_16X16;
  else
    Address = ((MSB - 0xb0) * 94 + LSB - 0xa1 + 846) * 32 + BaseAdd_16X16;
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_RESET);
  GT_SendAddr(Address);
  HAL_SPI_Receive(&hspi1, font, 32, 0xff);
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_SET);
}

void GT_FontGetHZ24(uint16_t str, uint8_t* font)
{
  uint32_t Address;
  uint8_t MSB, LSB;
  MSB = str>>8;
  LSB = str;
  if(MSB > 0xa0 && MSB < 0xaa)
    Address = ((MSB - 0xa1) * 94 + LSB - 0xa1) * 72 + BaseAdd_24X24;
  else
    Address = ((MSB - 0xb0) * 94 + LSB - 0xa1 + 846) * 72 + BaseAdd_24X24;
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_RESET);
  GT_SendAddr(Address);
  HAL_SPI_Receive(&hspi1, font, 72, 0xff);
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_SET);
}

void GT_FontGetHZ32(uint16_t str, uint8_t* font)
{
  uint32_t Address;
  uint8_t MSB, LSB;
  MSB = str>>8;
  LSB = str;
  if(MSB > 0xa0 && MSB < 0xaa)
    Address = ((MSB - 0xa1) * 94 + LSB - 0xa1) * 128 + BaseAdd_32X32;
  else
    Address = ((MSB - 0xb0) * 94 + LSB - 0xa1 + 846) * 128 + BaseAdd_32X32;
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_RESET);
  GT_SendAddr(Address);
  HAL_SPI_Receive(&hspi1, font, 128, 0xff);
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_SET);
}

void GT_FontGetASCII7(uint8_t str, uint8_t* font)
{
  uint32_t Address;
  Address = (str - 0x20) * 8 + ASCIIAdd_5X7;
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_RESET);
  GT_SendAddr(Address);
  HAL_SPI_Receive(&hspi1, font, 8, 0xff);
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_SET);
}

void GT_FontGetASCII8(uint8_t str, uint8_t* font)
{
  uint32_t Address;
  Address = (str - 0x20) * 8 + ASCIIAdd_7X8;
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_RESET);
  GT_SendAddr(Address);
  HAL_SPI_Receive(&hspi1, font, 8, 0xff);
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_SET);
}

void GT_FontGetASCII12(uint8_t str, uint8_t* font)
{
  uint32_t Address;
  Address = (str - 0x20) * 12 + ASCIIAdd_6X12;
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_RESET);
  GT_SendAddr(Address);
  HAL_SPI_Receive(&hspi1, font, 12, 0xff);
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_SET);
}

void GT_FontGetASCII16(uint8_t str, uint8_t* font)
{
  uint32_t Address;
  Address = (str - 0x20) * 16 + ASCIIAdd_8X16;
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_RESET);
  GT_SendAddr(Address);
  HAL_SPI_Receive(&hspi1, font, 16, 0xff);
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_SET);
}

void GT_FontGetASCII24(uint8_t str, uint8_t* font)
{
  uint32_t Address;
  Address = (str - 0x20) * 48 + ASCIIAdd_12X24;
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_RESET);
  GT_SendAddr(Address);
  HAL_SPI_Receive(&hspi1, font, 48, 0xff);
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_SET);
}

void GT_FontGetASCII32(uint8_t str, uint8_t* font)
{
  uint32_t Address;
  Address = (str - 0x20) * 64 + ASCIIAdd_16X32;
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_RESET);
  GT_SendAddr(Address);
  HAL_SPI_Receive(&hspi1, font, 64, 0xff);
  HAL_GPIO_WritePin(FONT_CS_GPIO_Port, FONT_CS_Pin, GPIO_PIN_SET);
}
